#include <iostream>
using namespace std;

class Animal   
{//动物
    public:
       Animal()
       {
        	cout << "Animal"<<endl;
       }
       virtual ~Animal()
       {
        	cout << "Animal close"<<endl;
       }
       string  getname()
       { 
            return name;
       }
       void  hoot()
       { 
            cout << "叫声"<<endl;
       }
    private:
    string name;
};

class Dog : public Animal  
{//狗
    public:
       Dog()
       {
            cout << "Dog"<<endl;
       }
       virtual ~Dog()
       {
            cout << "Dog close"<<endl;
       }
       string  getname()
       { 
            return name;
       }
       void  hoot()
       { 
            cout << "汪汪汪"<<endl;
       }
    private:
    string name="狗";
    string id="默认名称";
};
class Cat : public Animal  
{//猫
    public:
       Cat()
       {
            cout << "Cat"<<endl;
       }
       virtual ~Cat()
       {
            cout << "Cat close"<<endl;
       }
       string  getname()
       { 
            return name;
       }
       void  hoot()
       { 
            cout << "喵喵喵"<<endl;
       }
    private:
    string name="猫";
};
class SheepDog : public Dog  
{//牧羊犬
    public:
       SheepDog()
       {
            cout << "SheepDog"<<endl;
       }
       ~SheepDog()
       {
            cout << "SheepDog close"<<endl;
       }
       string  getname()
       { 
            return id;
       }
       void  hoot()
       { 
            cout << "汪汪汪"<<endl;
       }
    private:
    string name="牧羊犬";
    string id="谁谁谁的狗";
};
class SledDog : public Dog  
{// 雪橇犬
    public:
       SledDog()
       {
            cout << "SledDog"<<endl;
       }
       ~SledDog()
       {
            cout << "SledDog close"<<endl;
       }
       string  getname()
       { 
            return id;
       }
       void  hoot()
       { 
            cout << "汪汪汪"<<endl;
       }
    private:
    string name=" 雪橇犬";
    string id="雪雪雪狗";
};
class GardenCat : public Cat  
{//花园猫
    public:
       GardenCat()
       {
            cout << "GardenCat"<<endl;
       }
       ~GardenCat()
       {
            cout << "GardenCat close"<<endl;
       }
       string  getname()
       { 
            return id;
       }
       void  hoot()
       { 
        cout << "喵喵喵"<<endl;
       }
    private:
    string name="花园猫";
    string id="花花花猫";
};
class Garfield  : public Cat  
{//加菲猫
    public:
       Garfield ()
       {
            cout << "Garfield "<<endl;
       }
       ~Garfield ()
       {
            cout << "Garfield  close"<<endl;
       }
       string  getname()
       { 
            return id;
       }
       void  hoot()
       { 
            cout << "千层面"<<endl;
       }
    private:
    string name="加菲猫";
    string id="加加加菲";
};
int main()
{
     SheepDog dog1;
     SledDog dog2;
     cout <<"这是"<<dog1.getname()<<endl;
     dog1.hoot();
     // 基类隐藏
     cout<<"这是"<<dog2.getname()<<"属于狗类"<<dog2.Dog::getname()<<endl;
     cout<<"============="<< endl;
     //Cat cat0;
     Garfield cat1;
     GardenCat cat2;
     //使用派生类给基类(相对)复制
     //cat0 =cat1;
     cout<<"这是"<<cat1.getname()<<endl;
     cat1.hoot();
     cout <<"这是"<<cat2.getname()<<"属于猫类"<<cat2.Cat::getname()<<endl;
    //使用虚构函数，防止内存泄漏
     //Cat *p= new Garfield;
    // cout <<"这是"<< p->getname()<<endl;
    // p->hoot();
    // delete p;
    // p=nullptr;
     cout<<"============="<< endl;
    return 0;
}